import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.log4j.BasicConfigurator;

/**
 * 创建时间：2018-09-09
 * <p>修改时间：2018-09-09
 * <p>类说明：
 *
 * @author peng
 * @version 1.0
 */
public class WordCount {
    public static void main(String[] args) throws Exception {
        System.setProperty("hadoop.home.dir", "/usr/local/Cellar/hadoop/3.1.1/libexec");

        if (args.length != 2) {
            System.out.println("Usage: word-count <in> <out>");
            System.exit(2);
        }
        BasicConfigurator.configure();

        Job job = new Job();
        job.setJarByClass(WordCount.class);
        job.setJobName("Word count");

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
